﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lg.Core.Form.Types
{
    /// <summary>
    /// input typte="text" 验证数字类型
    /// </summary>
    public class Number:BaseType,IType
    {
        public bool AllowDecimals { get; set; }
        /// <summary>
        /// 数字取值范围，分割符"~",例：10~15.5（double类型解析）
        /// </summary>
        public List<int?>? Range { get; set; }
        /// <summary>
        /// 货币格式化类型
        /// </summary>
        public string? CurrencyFormat { get; set; }
        public void Verify()
        {
            if (this.IsRender)
            {
                if (Required)
                {
                    Validate.Required(Value);
                }
                Validate.Number(Value, Range, true, $"字段：{Title}较验未通过！");
            }
        }

        public void GetSaveDbValue(Dictionary<string, dynamic> formData, string inputValue)
        {
            formData.Add(Name, inputValue);
        }
    }
}
